home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / vidhandl / unhigh.cpp < prev    next >
C/C++ Source or Header  |  1999-02-03  |  2KB  |  71 lines

  1. /* UNHIGH - Utility to unhighlight higlighted lines in VIDEOHLP.TXT      */
  2. /* By Márcio Afonso Arimura Fialho                                       */
  3. /* Freeware/Public Domain                                                */
  4.  
  5. #include <STDIO.H>
  6. #include <CONIO.H>
  7.  
  8. void main ()
  9.  {
  10.     FILE *source,*target;
  11.     char *sourcename="VIDEOHLP.TXT"; //source filename
  12.     char *targetname="VIDEOHLP.TMP"; //target filename
  13.     int a0;
  14.     int c;
  15.     int linepos;
  16.  
  17.     source=fopen(sourcename,"rb"); //open source file
  18.     if (source==NULL)
  19.      {
  20.         printf ("\nERROR:Couldn't open %s to read",sourcename);
  21.         fcloseall();
  22.         return;
  23.      }
  24.  
  25.     target=fopen(targetname,"rb"); //verifies if target file already exists
  26.     if (target!=NULL)
  27.      {
  28.         printf ("\nWARNING: Target file already exists. Overwrite ? (Y/N)");
  29.         fclose (target);
  30.         a0=getch();
  31.         if (a0!='y' && a0!='Y')
  32.          {
  33.             printf ("\nReturning to OS");
  34.             fcloseall();
  35.             return;
  36.          }
  37.         printf ("\nOverwriting target file");
  38.      }
  39.  
  40.     target=fopen(targetname,"wb"); //open target file for writing
  41.     if (target==NULL)
  42.      {
  43.         printf ("\nERROR:Couldn't open %s to write",targetname);
  44.         fcloseall ();
  45.         return;
  46.      }
  47.  
  48.     linepos=0; //linepos indicates character column in row.
  49.  
  50.  //replaces every occurence of % character at the beginning of each row
  51.  //in source file by a blank space in target file.
  52.     for(;;)
  53.      {
  54.         c=fgetc(source);
  55.         if (c==EOF)
  56.             break;
  57.         if (c==0x0a || c==0x0d)
  58.             linepos=0;
  59.          else
  60.             linepos++;
  61.         if (c=='%' && linepos==1) //if '%' is the first character of the row
  62.             c=0x20; //c=' '
  63.         fputc (c,target);
  64.      }
  65.     fclose(target);
  66.     fclose(source);
  67.  }
  68.  
  69. // htpp://pessoal.iconet.com.br/jlfialho
  70. // E-mail: jlfialho@iconet.com.br
  71.